//package com.dimong.www.loan.ui.act.account;
//
//import java.io.File;
//import java.text.SimpleDateFormat;
//import java.util.Calendar;
//
//import android.app.Activity;
//import android.content.Intent;
//import android.net.Uri;
//import android.os.Bundle;
//import android.os.Message;
//import android.provider.MediaStore;
//import android.view.Gravity;
//import android.view.LayoutInflater;
//import android.view.View;
//import android.view.View.OnClickListener;
//import android.widget.Button;
//import android.widget.EditText;
//import android.widget.ImageView;
//import android.widget.PopupWindow;
//import android.widget.RadioGroup;
//import android.widget.RadioGroup.OnCheckedChangeListener;
//import android.widget.TextView;
//
//import com.bumptech.glide.Glide;
//import com.bumptech.glide.load.engine.DiskCacheStrategy;
//import com.jimi.skinsecret.R;
//import com.jimi.skinsecret.app.MyApplication;
//import com.jimi.skinsecret.broadcast.BroadcastHelper;
//import com.jimi.skinsecret.broadcast.BroadcastName;
//import com.jimi.skinsecret.controller.QiniuController;
//import com.jimi.skinsecret.controller.QiniuController.ImageUploadCallback;
//import com.jimi.skinsecret.db.JimiDBHelper;
//import com.jimi.skinsecret.http.HttpUtil;
//import com.jimi.skinsecret.http.OnFunctionListener;
//import com.jimi.skinsecret.image.glide.CircleTransform;
//import com.jimi.skinsecret.ui.UIHelper;
//import com.jimi.skinsecret.ui.base.BaseActivity;
//import com.jimi.skinsecret.ui.popopwindow.PopupwindowHelper;
//import com.jimi.skinsecret.ui.widget.ActionBarView;
//import com.jimi.skinsecret.ui.widget.ActionBarView.OnRightButtonClickListener;
//import com.jimi.skinsecret.ui.widget.MaterialDialog;
//import com.jimi.skinsecret.ui.widget.wheelview.WheelArea;
//import com.jimi.skinsecret.ui.widget.wheelview.WheelDate;
//import com.jimi.skinsecret.utils.PathUtil;
//import com.jimi.skinsecret.utils.PictureHelper;
//import com.xinlan.imageedit.editimage.CropAvatarActivity;
//
//public class EditUserInfoActivity extends BaseActivity implements OnClickListener {
//	private ActionBarView title;
//	private PopupWindow popupWindow;
//	private String avatarUrl;
//	private Uri imageUri = Uri.fromFile(new File(PathUtil.getInstance().getTempPath().getAbsolutePath(), "sowotemp.jpg"));
//	private int[] item = new int[] { 0, 0, 0 };
//
//	private ImageView register_avatar;
//
//	private TextView register_area;
//	private TextView register_birthday;
//	private EditText register_nikename;
//
//	private View register_birthday_layout;
//	private View register_area_layout;
//
//	private String uname;
//	private int sex = 0;
//	private String birthDay = "";
//	private String stayIn = "";
//	private long avatarId;
//	private Button register_submit;
//
//	private WheelDate wheelDate;
//	private MaterialDialog timeMD;
//	private WheelArea wheelarea;
//	private MaterialDialog areaMD;
//
//	private boolean isRegister;
//
//	private RadioGroup register_sex;
//
//	@Override
//	protected void handleActivityMessage(Message msg) {
//		super.handleActivityMessage(msg);
//		switch (msg.what) {
//		case 1:
//			showToast("聊天服务器连接不上");
//			break;
//		default_log:
//			break;
//		}
//	}
//
//	@Override
//	public void onCreate(Bundle savedInstanceState) {
//		super.onCreate(savedInstanceState);
//		setContentView(R.layout.act_register_second);
//		title = (ActionBarView) findViewById(R.id.title);
//		register_avatar = (ImageView) findViewById(R.id.register_avatar);
//		register_area = (TextView) findViewById(R.id.register_area);
//		register_birthday = (TextView) findViewById(R.id.register_birthday);
//		register_nikename = (EditText) findViewById(R.id.register_nikename);
//
//		register_birthday_layout = findViewById(R.id.register_birthday_layout);
//		register_birthday_layout.setOnClickListener(this);
//		register_area_layout = findViewById(R.id.register_area_layout);
//		register_area_layout.setOnClickListener(this);
//		register_avatar.setOnClickListener(this);
//
//		register_submit = (Button) findViewById(R.id.register_submit);
//		register_submit.setOnClickListener(this);
//
//		register_sex = (RadioGroup) findViewById(R.id.register_sex);
//		if (MyApplication.user != null) {
//			if (MyApplication.user.getAvatarId() != null) {
//				avatarId = MyApplication.user.getAvatarId();
//				Glide.with(mContext).load(HttpUtil.getAvatar(MyApplication.user.getAvatarId())).transform(new CircleTransform(mContext)).placeholder(R.drawable.avatar).into(register_avatar);
//			}
//			if (MyApplication.user.getSex() != null) {
//				sex = MyApplication.user.getSex();
//				if (sex == 0) {
//					register_sex.check(R.id.register_female);
//				} else {
//					register_sex.check(R.id.register_male);
//				}
//			}
//			if (MyApplication.user.getBirthday() != null) {
//				birthDay = MyApplication.user.getBirthday();
//				if (!birthDay.equals("")) {
//					register_birthday.setText(birthDay);
//				}
//			}
//			if (MyApplication.user.getUname() != null) {
//				register_nikename.setText(MyApplication.user.getUname());
//			}
//			if (MyApplication.user.getStayIn() != null) {
//				stayIn = MyApplication.user.getStayIn();
//				if (!stayIn.equals("")) {
//					register_area.setText(JimiDBHelper.getInstance().getCityDBHelper().getArea(MyApplication.user.getStayIn() + ""));
//				}
//			}
//		}
//
//		register_sex.setOnCheckedChangeListener(new OnCheckedChangeListener() {
//
//			@Override
//			public void onCheckedChanged(RadioGroup group, int checkedId) {
//				if (R.id.register_male == checkedId) {
//					sex = 1;
//				} else if (R.id.register_female == checkedId) {
//					sex = 0;
//				}
//			}
//		});
//		initTitle();
//	}
//
//	private void initTitle() {
//		isRegister = getIntent().getBooleanExtra("isRegister", false);
//		title.setTitle("基本资料");
//		title.setBack(this);
//		if (isRegister) {
//			title.setRightButton("下一步", new OnRightButtonClickListener() {
//				@Override
//				public void onClick(View button) {
//					HttpUtil.editUserProfile(avatarId, uname, sex, birthDay, stayIn, new OnFunctionListener() {
//						@Override
//						public void onSuccess(Object object) {
//							MyApplication.user.setAvatarId(avatarId);
//							MyApplication.user.setUname(uname);
//							MyApplication.user.setBirthday(birthDay);
//							MyApplication.user.setStayIn(stayIn);
//							MyApplication.user.setSex(sex);
//							UIHelper.OpenRegisterThird(mContext);
//						}
//					});
//				}
//			});
//		} else {
//			title.setTitle("资料编辑");
//			register_submit.setText("保存");
//		}
//	}
//
//	private void selectTime() {
//		final SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
//		LayoutInflater inflater = LayoutInflater.from(this);
//		final View timepickerview = inflater.inflate(R.layout.view_three_picker, null);
//		wheelDate = new WheelDate(this, timepickerview);
//		String time = register_birthday.getText().toString();
//		Calendar calendar = Calendar.getInstance();
//		try {
//			calendar.setTime(dateFormat.parse(time));
//		} catch (Exception e) {
//		}
//		int year = calendar.get(Calendar.YEAR);
//		int month = calendar.get(Calendar.MONTH);
//		int day = calendar.get(Calendar.DAY_OF_MONTH);
//		wheelDate.initDateTimePicker(year, month, day);
//		if (timeMD == null || !timeMD.isShowing()) {
//			timeMD = new MaterialDialog(this).setTitle("选择时间").setContentView(timepickerview).setPositiveButton("确定", new OnClickListener() {
//				@Override
//				public void onClick(View arg0) {
//					try {
//						Calendar calendar = Calendar.getInstance();
//						calendar.setTime(dateFormat.parse(wheelDate.getTime()));
//						if (calendar.compareTo(Calendar.getInstance()) == 1) {
//							showToast("时间必须小于今天");
//						} else {
//							String str = wheelDate.getTime();
//							register_birthday.setText(str);
//							birthDay = str;
//						}
//					} catch (Exception e) {
//					}
//					timeMD.dismiss();
//				}
//			}).setNegativeButton("取消", new OnClickListener() {
//				@Override
//				public void onClick(View arg0) {
//					timeMD.dismiss();
//				}
//			});
//			timeMD.show();
//		}
//	}
//
//	private void selectArea() {
//		LayoutInflater inflater = LayoutInflater.from(mContext);
//		final View areapicker = inflater.inflate(R.layout.view_three_picker, null);
//		wheelarea = new WheelArea(mContext, areapicker);
//		wheelarea.initAreaPicker(item, mContext);
//		if (areaMD == null || !areaMD.isShowing()) {
//			areaMD = new MaterialDialog(mContext).setTitle("选择地区").setContentView(areapicker).setPositiveButton("确定", new OnClickListener() {
//				public void onClick(View arg0) {
//					try {
//						item = wheelarea.getItem();
//						stayIn = wheelarea.getId();
//						register_area.setText(JimiDBHelper.getInstance().getCityDBHelper().getArea(stayIn + ""));
//					} catch (Exception e) {
//					}
//					areaMD.dismiss();
//				}
//
//			}).setNegativeButton("取消", new OnClickListener() {
//				@Override
//				public void onClick(View arg0) {
//					areaMD.dismiss();
//				}
//			});
//			areaMD.show();
//		}
//	}
//
//	private void updata() {
//		if (popupWindow == null) {
//			popupWindow = PopupwindowHelper.getInstance(this).createPicPopupWindow(new OnClickListener() {
//				@Override
//				public void onClick(View arg0) {
//					switch (arg0.getId()) {
//					case R.id.popup_pic_camera:
//						Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
//						intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);
//						startActivityForResult(intent, PictureHelper.REQUEST_CODE_GETIMAGE_BYCAMERA);
//						break;
//					case R.id.popup_pic_photo:
//						PictureHelper.startCropGallery(mContext, true);
//						break;
//					default_log:
//						break;
//					}
//					popupWindow.dismiss();
//				}
//			});
//		}
//		popupWindow.showAtLocation(findViewById(R.id.register_second), Gravity.CENTER_HORIZONTAL | Gravity.BOTTOM, 0, 0);
//
//	}
//
//	@Override
//	protected void onActivityResult(int requestCode, int resultCode, Intent data) {
//		super.onActivityResult(requestCode, resultCode, data);
//		if (resultCode == Activity.RESULT_CANCELED) {
//			return;
//		}
//		switch (requestCode) {
//		case PictureHelper.REQUEST_CODE_GETIMAGE_BYCAMERA:
//			Intent it = new Intent(mContext, CropAvatarActivity.class);
//			it.putExtra(CropAvatarActivity.FILE_PATH, PictureHelper.getRealFilePath(mContext, imageUri));
//			File outputFile = new File(PathUtil.getInstance().getTempPath().getAbsolutePath(), "jimieditpic.jpg");
//			it.putExtra(CropAvatarActivity.EXTRA_OUTPUT, outputFile.getAbsolutePath());
//			it.putExtra("isAvatar", true);
//			this.startActivityForResult(it, PictureHelper.REQUEST_CODE_GETIMAGE_BYCROP);
//			break;
//		case PictureHelper.REQUEST_CODE_GETIMAGE_BYCROP:
//			avatarUrl = data.getStringExtra("save_file_path");
//			Glide.with(mContext).load(avatarUrl).diskCacheStrategy(DiskCacheStrategy.NONE).skipMemoryCache(true).transform(new CircleTransform(mContext)).placeholder(R.drawable.avatar)
//					.into(register_avatar);
//			QiniuController.avatarUpload(mContext, avatarUrl, new ImageUploadCallback() {
//				@Override
//				public void uploadSuccess(long imgId) {
//					avatarId = imgId;
//				}
//
//				@Override
//				public void uploadFail() {
//				}
//			});
//			break;
//		}
//	}
//
//	@Override
//	public void onClick(View v) {
//		switch (v.getId()) {
//		case R.id.register_birthday_layout:
//			selectTime();
//			break;
//		case R.id.register_area_layout:
//			selectArea();
//			break;
//		case R.id.register_avatar:
//			updata();
//			break;
//		case R.id.register_submit:
//			uname = register_nikename.getText().toString();
//			if (birthDay.equals("")) {
//				birthDay = "2010-01-01";
//			}
//			if (stayIn.equals("")) {
//				stayIn = "110101";
//			}
//
//			HttpUtil.editUserProfile(avatarId, uname, sex, birthDay, stayIn, new OnFunctionListener() {
//				@Override
//				public void onSuccess(Object object) {
//					MyApplication.user.setAvatarId(avatarId);
//					MyApplication.user.setUname(uname);
//					MyApplication.user.setBirthday(birthDay);
//					MyApplication.user.setStayIn(stayIn);
//					MyApplication.user.setSex(sex);
//					if (isRegister) {
//						UIHelper.OpenRegisterThird(mContext);
//					} else {
//						JimiDBHelper.getInstance().getUserInfoDBHelper().saveUserInfo(MyApplication.user);
//						BroadcastHelper.getInstance().sendBroadCast(mContext, BroadcastName.BROADCAST_ACTION_REFRESH_USER);
//						finish();
//					}
//				}
//			});
//			break;
//		default_log:
//			break;
//		}
//	}
//}
